import { S } from '../../s';
import { IPSAppDELogic } from '../../app/dataentity/ipsapp-delogic';
import { IPSDELogic } from './ipsdelogic';
import { IPSDELogicNode } from './ipsdelogic-node';
import { IPSDELogicParam } from './ipsdelogic-param';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDELogicImpl
  extends PSModelObjectImpl
  implements IPSDELogic, IPSAppDELogic
{
  get codeName(): string {
    return this.M.codeName;
  }

  get debugMode(): 0 | 1 {
    return this.M.debugMode != null ? this.M.debugMode : 0;
  }

  get defaultParamName(): string {
    return this.M.defaultParamName;
  }

  get logicName(): string {
    return this.M.logicName;
  }

  get logicSubType():
    | 'NONE'
    | 'DEFIELD'
    | 'USER'
    | 'USER2'
    | 'USER3'
    | 'USER4' {
    return this.M.logicSubType || 'NONE';
  }

  protected psdelogicnodes: IPSDELogicNode[];
  getPSDELogicNodes(): IPSDELogicNode[] | null {
    return (
      this.psdelogicnodes ||
      (this.psdelogicnodes = this.fillChildListModel(
        this.M.getPSDELogicNodes,
        S._1dd,
      ) as IPSDELogicNode[])
    );
  }

  findPSDELogicNode(objKey: any): IPSDELogicNode | null {
    return this.getPSModel5(
      S._1dd,
      this.getPSDELogicNodes(),
      objKey,
    ) as IPSDELogicNode;
  }

  protected psdelogicparams: IPSDELogicParam[];
  getPSDELogicParams(): IPSDELogicParam[] | null {
    return (
      this.psdelogicparams ||
      (this.psdelogicparams = this.fillChildListModel(
        this.M.getPSDELogicParams,
        S._1e1,
      ) as IPSDELogicParam[])
    );
  }

  findPSDELogicParam(objKey: any): IPSDELogicParam | null {
    return this.getPSModel5(
      S._1e1,
      this.getPSDELogicParams(),
      objKey,
    ) as IPSDELogicParam;
  }

  get scriptCode(): string {
    return this.M.scriptCode;
  }

  protected startpsdelogicnode: IPSDELogicNode;
  getStartPSDELogicNode(): IPSDELogicNode | null {
    if (this.startpsdelogicnode != null) return this.startpsdelogicnode;
    const value = this.M.getStartPSDELogicNode;
    if (value == null) {
      return;
    }
    this.startpsdelogicnode = this.findPSDELogicNode(value);
    return this.startpsdelogicnode;
  }

  get customCode(): boolean {
    return this.M.customCode != null ? this.M.customCode : false;
  }

  get enableBackend(): boolean {
    return this.M.enableBackend;
  }

  get enableFront(): boolean {
    return this.M.enableFront;
  }
  get cls(): string {
    return 'PSDELogicImpl';
  }
  instanceof(cls: string): boolean {
    if (cls == S._1ff || cls == S._200) return true;
    return super.instanceof(cls);
  }
}
